home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
...taking it to the Macs!
/
...taking it to the Macs!.iso
/
Extras
/
ActiveX Mac SDK
/
ActiveX SDK
/
Common
/
debug.cpp
< prev
next >
Wrap
Text File
|
1997-01-03
|
3KB
|
149 lines
//
// DEBUG.CPP
//
// Copyright (C) Microsoft Corporation, 1996
//
#define CHECKMEMORYLEAKS
#define FAR
#include <ole2.h>
#include <dispatch.h>
#include <wintypes.h>
#include "debug.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <Types.h>
#pragma export on
#ifdef CHECKMEMORYLEAKS
#undef CoTaskMemAlloc
#undef CoTaskMemRealloc
#undef CoTaskMemFree
#define PTRTABLEENTRIES 512
static BOOL fFirst = TRUE;
static LPVOID PtrTable[PTRTABLEENTRIES];
ULONG g_cAllocations = 0;
void *
DebugCoTaskMemAlloc(unsigned long cb)
{
LPVOID ptr;
if (fFirst) {
memset(PtrTable, 0, sizeof(PtrTable));
fFirst = FALSE;
}
ptr = CoTaskMemAlloc(cb);
if (ptr != NULL) {
int i;
for (i = 0; i < PTRTABLEENTRIES; i++) {
if (PtrTable[i] == NULL) {
PtrTable[i] = ptr;
g_cAllocations++;
break;
}
}
if (i == PTRTABLEENTRIES) {
DebugPrintf("eek, too many allocations for debug"); Debugger();
}
}
return ptr;
}
void *
DebugCoTaskMemRealloc(void * pv, unsigned long cb)
{
LPVOID ptr;
if (pv == NULL) {
DebugPrintf("CoTaskMemRealloc: pv==NULL"); Debugger();
} else {
int i;
for (i = 0; i < PTRTABLEENTRIES; i++) {
if (PtrTable[i] == pv) {
PtrTable[i] = NULL;
g_cAllocations--;
break;
}
}
if (i == PTRTABLEENTRIES) {
DebugPrintf("CoTaskMemRealloc: %x not found, pv"); Debugger();
}
}
ptr = CoTaskMemRealloc(pv, cb);
if (ptr != NULL) {
int i;
for (i = 0; i < PTRTABLEENTRIES; i++) {
if (PtrTable[i] == NULL) {
PtrTable[i] = ptr;
g_cAllocations++;
break;
}
}
if (i == PTRTABLEENTRIES) {
DebugPrintf("eek, too many allocations for debug"); Debugger();
}
}
return ptr;
}
void
DebugCoTaskMemFree(void * pv)
{
if (pv == NULL) {
DebugPrintf("CoTaskMemFree: pv==NULL"); Debugger();
} else {
int i;
for (i = 0; i < PTRTABLEENTRIES; i++) {
if (PtrTable[i] == pv) {
PtrTable[i] = NULL;
g_cAllocations--;
break;
}
}
if (i == PTRTABLEENTRIES) {
DebugPrintf("CoTaskMemFree: %x not found", pv); Debugger();
}
}
CoTaskMemFree(pv);
}
#endif
void
DebugPrintf(
char * lpFormatString,
...
)
{
#if 0 //jjo
va_list arglist;
char Buffer[256];
va_start(arglist, lpFormatString);
vsprintf(Buffer, lpFormatString, arglist);
strcat(Buffer, ";g");
va_end(arglist);
debugstr(Buffer);
#else
#pragma unused (lpFormatString)
#endif
}
#pragma export off